package com.example.demo.listen;

import com.example.demo.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class ListenerTest {

    @EventListener
    @Async
    public void email(User user) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("user info = {}", user);
    }

    @EventListener
    @Order(100)
    public void email2(User user) {
        log.info("order 100,{}",user);
    }

    @EventListener
    @Order(50)
    public void email3(User user) {
        log.info("order 50,{}",user);
    }

    @EventListener(value = Date.class)
    @Order(50)
    public void email4(Date date) {
        log.info("date info ,{}",date);
    }

}
